<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@ include file="../../common/tag.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<LINK href="../resource/css/frame.css" type="text/css" rel="stylesheet">
		<link rel="stylesheet" href="<%=basePath %>/resource/ztree/zTreeStyleForDemo.css" type="text/css">
	<script type="text/javascript" src="<%=basePath %>/resource/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="<%=basePath %>/resource/js/jquery.ztree.core-3.2.js"></script>
<script type="text/javascript">
	var curMenu = null, zTree_Menu = null;
		var setting = {
			view: {
				showLine: true,
				selectedMulti: false,
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onNodeCreated: this.onNodeCreated,
				beforeClick: this.beforeClick,
				onClick: this.onClick
			}
		};

		var zNodes =[
		 			{ id:1, pId:0, name:"主菜单 1",url:""},
					{ id:11, pId:1, name:"子菜单 1-1",url:"http://baidu.com"},
					{ id:111, pId:11, name:"叶子节点 1-1-1",url:"http://baidu.com"},
					{ id:112, pId:11, name:"叶子节点 1-1-2",url:"http://baidu.com"},
					{ id:113, pId:11, name:"叶子节点 1-1-3",url:"http://baidu.com"},
					{ id:114, pId:11, name:"叶子节点 1-1-4",url:"http://baidu.com"},
					{ id:12, pId:1, name:"子菜单 1-2",url:"http://baidu.com"},
					{ id:121, pId:12, name:"叶子节点 1-2-1",url:"http://baidu.com"},
					{ id:122, pId:12, name:"叶子节点 1-2-2",url:"http://baidu.com"},
					{ id:123, pId:12, name:"叶子节点 1-2-3",url:"http://baidu.com"},
					{ id:124, pId:12, name:"叶子节点 1-2-4",url:"http://baidu.com"},
					
		];

		function beforeClick(treeId, node) {
			if (node.isParent) {
				if (node.level === 0) {
					var pNode = curMenu;
					while (pNode && pNode.level !==0) {
						pNode = pNode.getParentNode();
					}
					if (pNode !== node) {
						var a = $("#" + pNode.tId + "_a");
						a.removeClass("cur");
						zTree_Menu.expandNode(pNode, false);
					}
					a = $("#" + node.tId + "_a");
					a.addClass("cur");

					var isOpen = false;
					for (var i=0,l=node.children.length; i<l; i++) {
						if(node.children[i].open) {
							isOpen = true;
							break;
						}
					}
					if (isOpen) {
						zTree_Menu.expandNode(node, true);
						curMenu = node;
					} else {
						zTree_Menu.expandNode(node.children[0].isParent?node.children[0]:node, true);
						curMenu = node.children[0];
					}
				} else {
					zTree_Menu.expandNode(node);
				}
			}
			return !node.isParent;
		}
		function onClick(e, treeId, node) {
			alert("Do what you want to do!");
		}

		$(document).ready(function(){
			$.ajax({
				url:"../menu/queryAuthMenu.action",
				type:"GET",
				cache:false,
				async:false,
				error:function(json){
					 alert('Error loading XML document');
			         return false;
				},
				success:function(json){
					$.fn.zTree.init($("#menuTree"), setting, zNodes);
				}
			});
			zTree_Menu = $.fn.zTree.getZTreeObj("treeDemo");
			curMenu = zTree_Menu.getNodes()[0].children[0].children[0];
			zTree_Menu.selectNode(curMenu);
			var a = $("#" + zTree_Menu.getNodes()[0].tId + "_a");
			a.addClass("cur");
		});
		//-->
	</SCRIPT>
	<style type="text/css">
.ztree li a.level0 {width:200px;height: 20px; text-align: center; display:block; background-color: #0B61A4; border:1px silver solid;}
.ztree li a.level0.cur {background-color: #66A3D2; }
.ztree li a.level0 span {display: block; color: white; padding-top:3px; font-size:12px; font-weight: bold;word-spacing: 2px;}
.ztree li a.level0 span.button {	float:right; margin-left: 10px; visibility: visible;display:none;}
.ztree li span.button.switch.level0 {display:none;}
	</style>
 </HEAD>

<BODY>
				<div id="demo_menu" class="demo_menu left">
					<ul id="menuTree" class="ztree"></ul>
				</div>
</BODY>
</HTML>